﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using Senbo.Mvc;
using System.Data.Entity;
using Senbo.Model;
using Senbo.Model.Entities;

namespace Senbo.Web
{
    // Note: For instructions on enabling IIS6 or IIS7 classic mode, 
    // visit http://go.microsoft.com/?LinkId=9394801

    public class MvcApplication : System.Web.HttpApplication
    {
        public static void RegisterGlobalFilters(GlobalFilterCollection filters)
        {
            filters.Add(new HandleErrorAttribute());
        }

        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
            //routes.IgnoreRoute("{resource}.js/{*pathInfo}");
            //routes.IgnoreRoute("upload/{*.pathInfo}");
            //routes.IgnoreRoute("Content/{*.pathInfo}");
            //routes.IgnoreRoute("Scripts/{*.pathInfo}");
            //routes.IgnoreRoute("Images/{*.pathInfo}");
            //routes.IgnoreRoute("{*alljs}", new { alljs = @".*\.js(/.*)?" });
            //routes.IgnoreRoute("{*allasp}", new { allasp = @".*\.asp(/.*)?" });
            //routes.IgnoreRoute("{*allphp}", new { allphp = @".*\.php(/.*)?" });
            //routes.IgnoreRoute("{*allico}", new { allico = @".*\.ico(/.*)?" });
            //routes.IgnoreRoute("{*allrar}", new { allrar = @".*\.rar(/.*)?" });
            //routes.IgnoreRoute("{*alljpg}", new { allrar = @".*\.jpg(/.*)?" });
            //routes.IgnoreRoute("{*allgif}", new { allrar = @".*\.gif(/.*)?" });
            //routes.IgnoreRoute("{*allpng}", new { allrar = @".*\.png(/.*)?" });
            //routes.IgnoreRoute("{*allv}", new { allv = @".*\.v(/.*)?" });

            routes.MapRoute(
                "Default", // Route name
                "{controller}/{action}/{id}", // URL with parameters
                new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
            );

        }

        protected void Application_Start()
        {
            //添加数据
            Database.SetInitializer<SenboDBContext>(new SenboIntializer());

            //IoC
            //Bootstrapper.ConfigureStructureMap();
            //ControllerBuilder.Current.SetControllerFactory(new StructureMapControllerFactory());

            AreaRegistration.RegisterAllAreas();

            RegisterGlobalFilters(GlobalFilters.Filters);
            RegisterRoutes(RouteTable.Routes);

            //Default controller
            ControllerBuilder.Current.DefaultNamespaces.Add("Senbo.Mvc.Controllers");
        }
    }
}